package net.joey.file;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;

public class ByteArrayStreamDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			File f = new File("PrintSteam.cc");
//			File f = new File("PrintSteam(utf-8).cc");
			BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			int r = -1;
			while((r = bis.read()) != -1){
				baos.write(r);
			}
			baos.close();
			bis.close();
			byte[] bs = baos.toByteArray();
			System.out.println(Arrays.toString(bs));
			for(byte b:bs){
				System.out.println(Integer.toHexString(b));
			}
//			String s = new String(bs,"gb2312");
//			String s = new String(bs,"utf-8");
//			System.out.println(s);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
